package modelgraph;

import java.util.ArrayList;
import java.util.List;

public class ModelGraphClass extends ModelGraphNode
{
	List<ModelGraphAttribute> attrs = new ArrayList<ModelGraphAttribute>();
	
	public List<ModelGraphAttribute> getAttrs()
	{
		return attrs;
	}
	
	public boolean addAttr(ModelGraphAttribute attr)
	{
		if (containsAttr(attr.getName()))
			return false;
		attrs.add(attr);
		attr.setHost(this);
		return true;
	}
	
	public boolean containsAttr(String name)
	{
		for (ModelGraphAttribute attr : attrs)
		{
			if (attr.getName().equals(name))
				return true;
		}
		return false;
	}
	
	public ModelGraphAttribute getAttrByName(String name)
	{
		for (ModelGraphAttribute attr : attrs)
		{
			if (attr.getName().equals(name))
			{
				return attr;
			}
		}
		ModelGraphAttribute newattr = new ModelGraphAttribute();
		newattr.setName(name);
		this.addAttr(newattr);
		return newattr;
	}
}
